//
//  ArrivalGoodViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-5.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "ArrivalGoodViewController.h"
#import "ArrivalGoodTableViewCell.h"
#import "ConfirmArrivalTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "GuideListTableViewCell.h"
#import "UpCounterDetailTableViewCell.h"
#import "EGORefreshTableHeaderView.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
@interface ArrivalGoodViewController ()<ArrivalGoodTableViewCellDelegate,EGORefreshTableHeaderDelegate,FilterViewControllerDelegate,CommonProductDetailDelegate>
{
    CommonProductDetailViewController *commonProductDetailVC;
    FilterViewController *filterVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    
    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
    NSMutableArray *arrivalNumArray;
    NSMutableArray *arrivalNumberArray;
    NSMutableArray *arrivalWeightArray;
    NSMutableArray *arrivalProductNameArray;
    NSMutableArray *arrivalGuideNameArray;
    NSMutableArray *arrivalDateArray;
    NSMutableArray *arrivalStatusArray;
    NSMutableArray *arrivalPriceArray;
    
    NSMutableArray *detailUrlArray;
    NSMutableArray *detailStoreAddressArray;
    NSMutableArray *detailProductNameArray;
     NSMutableArray *detailProductCodeArray;
    NSMutableArray *detailLinePriceArray;
    NSMutableArray *detailWeightArray;
     NSMutableArray *detailAttributesArray;
   
     NSMutableArray *detailLineIdArray;
    NSMutableArray *detailStatusArray;
    NSString *guideCodeStr;
    NSMutableArray *guideCodeArray;
     NSMutableArray *guideNameArray;
    
  //   NSMutableArray *contacts;
    NSMutableArray *selectLineID;
    
    BOOL isOpen;
    
    NSMutableArray *arrivalDetailUrlArray;
    NSMutableArray *arrivalDetailStoreAddressArray;
    NSMutableArray *arrivalDetailProductNameArray;
    NSMutableArray *arrivalDetailProductCodeArray;
    NSMutableArray *arrivalDetailLinePriceArray;
    NSMutableArray *arrivalReceiverArray;
    NSMutableArray *arrivalDetailWeightArray;
     NSMutableArray *arrivalDetailAttributesArray;
    NSMutableArray *arrivalDetailStatusArray;
    
    NSString *receiverGuideNameStr;
    
    UITextField *inputTextField;
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end

@implementation ArrivalGoodViewController
-(void)viewWillAppear:(BOOL)animated
{
    if ([_isLoad isEqualToString:@"N"]) {
        if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }

    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    
    [self initArrivalList];
    [self initConfirmArrival];
    [self initArrivalDetail];
    [self initOrderFilterView];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    }

}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"Delivery";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    
    [arrivalNumArray removeAllObjects];
    [arrivalProductNameArray removeAllObjects];
    [arrivalWeightArray removeAllObjects];
    [arrivalNumberArray removeAllObjects];
    [arrivalGuideNameArray removeAllObjects];
    [arrivalDateArray removeAllObjects];
    [arrivalStatusArray removeAllObjects];
    [arrivalPriceArray removeAllObjects];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
}
-(void)initArrivalDetail
{
    [_detailScrollView setContentOffset:CGPointMake(0, 0)];
    receiverGuideNameStr=@"";
    arrivalDetailUrlArray=[NSMutableArray array];
    arrivalDetailProductNameArray=[NSMutableArray array];
    arrivalDetailProductCodeArray=[NSMutableArray array];
    arrivalDetailStoreAddressArray=[NSMutableArray array];
    arrivalDetailLinePriceArray=[NSMutableArray array];
    arrivalReceiverArray=[NSMutableArray array];
    arrivalDetailWeightArray=[NSMutableArray array];
    arrivalDetailAttributesArray=[NSMutableArray array];
    arrivalDetailStatusArray=[NSMutableArray array];
    CGRect viewFrame=_arrivalDetailViewContainer.frame;
    viewFrame.origin.y=768;
    _arrivalDetailViewContainer.frame=viewFrame;
    [_arrivalDetailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_arrivalDetailAlphaView addTarget:self action:@selector(arrivalDetailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];

}
-(void)initArrivalList
{
    _searchTextField.text=@"";
    arrivalProductNameArray=[NSMutableArray array];
    arrivalNumArray=[NSMutableArray array];
    arrivalWeightArray=[NSMutableArray array];
    arrivalNumberArray=[NSMutableArray array];
    arrivalGuideNameArray=[NSMutableArray array];
    arrivalDateArray=[NSMutableArray array];
    arrivalStatusArray=[NSMutableArray array];
    arrivalPriceArray=[NSMutableArray array];
}
-(void)initConfirmArrival
{
    [_rightScrollView setContentOffset:CGPointMake(0, 0)];
    isOpen=NO;
    guideCodeStr=@"";
    detailUrlArray=[NSMutableArray array];
    detailStoreAddressArray=[NSMutableArray array];
    detailProductNameArray=[NSMutableArray array];
    detailProductCodeArray=[NSMutableArray array];
    detailLinePriceArray=[NSMutableArray array];
    detailWeightArray=[NSMutableArray array];
    detailAttributesArray=[NSMutableArray array];
    detailStatusArray=[NSMutableArray array];
    detailLineIdArray=[NSMutableArray array];
    selectLineID=[NSMutableArray array];
    guideCodeArray=[NSMutableArray array];
    guideNameArray=[NSMutableArray array];
 //    contacts = [NSMutableArray array];
    CGRect viewFrame=_confirmArrivalViewContainer.frame;
    viewFrame.origin.y=768;
    _confirmArrivalViewContainer.frame=viewFrame;
    [_confirmArrivalAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_confirmArrivalAlphaView addTarget:self action:@selector(confirmArrivalAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    _resultTextView.layer.borderColor=[[UIColor colorWithRed:239.0f/255.0f green:239.0f/255.0f blue:239.0f/255.0f alpha:1] CGColor];
    _resultTextView.layer.borderWidth= 1.0f;
    _resultTextView.layer.cornerRadius=3;
     [_resultGuideListBtn addTarget:self action:@selector(selectGuideBtnClick:) forControlEvents:UIControlEventTouchUpInside];

}
-(void)selectGuideBtnClick:(UIButton *)sender
{
    if (isOpen) {
        _resultGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];
            CGRect frame=_resultGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_resultGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpen=NO;
        }];
        
    }
    else
    {
        [self requestGuideList];
        _resultGuideListViewContainer.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
            
            
            [_resultGuideListArrowImage setImage:closeImage];
            CGRect frame=_resultGuideListViewContainer.frame;
            
            frame.size.height=657;
            [_resultGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpen=YES;
        }];
        
    }
    
}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                    NSMutableArray *mGuidesArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                   
                    [_resultGuideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                         [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)arrivalDetailAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];
     [_detailScrollView setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5 animations:^{
        
        
        CGRect frame=_arrivalDetailViewContainer.frame;
        
        frame.origin.y=768;
        [_arrivalDetailViewContainer setFrame:frame];
        
    } completion:^(BOOL finished){
        
    }];

}
-(void)confirmArrivalAlphaViewClick
{
    [_searchTextField resignFirstResponder];
    [_resultTextView resignFirstResponder];

    [selectLineID removeAllObjects];
    [_rightScrollView setContentOffset:CGPointMake(0, 0)];
    
    [UIView animateWithDuration:0.5 animations:^{
        CGRect framea=_rightScrollView.frame;
        
        framea.origin.y=0;
        [_rightScrollView setFrame:framea];
        
        CGRect frame=_confirmArrivalViewContainer.frame;
        
        frame.origin.y=768;
        [_confirmArrivalViewContainer setFrame:frame];
        
    } completion:^(BOOL finished){
        
    }];

}

-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=arrivalNumArray.count)
        return;
    if(oldPageNum == 0){
        [arrivalNumArray removeAllObjects];
        [_arrivalTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    [self requestDisplayList: _productPageIndex pageSize:6];
}
-(void)requestDisplayList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        // NSLog(@"paramsLIST====%@",params);
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
        
        [HttpRequest requestData:@"StoreManager/DeliveryList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                 //   NSLog(@"shopcartlist===%@",severDataDict.dataDict);
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _arrivalTotalCount.text=[NSString stringWithFormat:@"有%lu条记录",(unsigned long)_productTotalCount];
                    
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                    
                    NSMutableArray  *displayListArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //   int total=0;
                    if ( displayListArray.count>0) {
                        for (int i=0; i< displayListArray.count; i++) {
                            [arrivalNumArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [arrivalProductNameArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [arrivalNumberArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"Number"]];
                            [arrivalWeightArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            [arrivalGuideNameArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [arrivalDateArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [arrivalStatusArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [arrivalPriceArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            
                        }
                    }
                    
                    [_arrivalTableView reloadData];
                    
                   
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                         [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
     if (_refreshHeaderView == nil) {
    EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _arrivalTableView.bounds.size.height, self.view.frame.size.width, _arrivalTableView.bounds.size.height)];
    view.delegate = self;
    [_arrivalTableView addSubview:view];
    _refreshHeaderView = view;
    
    
}

//  update the last update date
[_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [arrivalNumArray removeAllObjects];
    [arrivalProductNameArray removeAllObjects];
    [arrivalWeightArray removeAllObjects];
    [arrivalNumberArray removeAllObjects];
    [arrivalGuideNameArray removeAllObjects];
    [arrivalDateArray removeAllObjects];
    [arrivalStatusArray removeAllObjects];
    [arrivalPriceArray removeAllObjects];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_arrivalTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
     if (scrollView==_arrivalTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
     }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_arrivalTableView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //    NSMutableArray *codeArrays = [NSMutableArray arrayWithArray:[shopCartData objectForKey:@"PRODUCTCODE"]];
    //    return [codeArrays count];
    if (tableView ==_arrivalTableView) {
        return arrivalNumArray.count;
    }
    else if (tableView==_detailTableView)
    {
        return detailUrlArray.count;
    }
    else if (tableView==_resultGuideListTableView)
    {
        return guideCodeArray.count;
    }
    else if (tableView==_arrivalDetailTableView)
    {
        return arrivalDetailUrlArray.count;
    }
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==_arrivalTableView||tableView==_detailTableView||tableView==_arrivalDetailTableView)
        return 120.0f;
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_arrivalTableView) {
        static NSString * identifier = @"Cell";
        ArrivalGoodTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ArrivalGoodTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
             cell.delegate=self;
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.confirmArrivalBtn.tag=indexPath.row;
        if (arrivalNumArray.count>0) {
            cell.numLabel.text=[NSString stringWithFormat:@"%@",[arrivalNumArray objectAtIndex:indexPath.row]];
           // [self resizeLabel:cell.numLabel];
            [Global resizeForLable:cell.numLabel WithText:cell.numLabel.text parentView:self.view];
            CGRect frame=cell.statusLabel.frame;
            frame.origin.x=cell.numLabel.frame.origin.x+cell.numLabel.frame.size.width;
            cell.statusLabel.frame=frame;
        }
        if (arrivalStatusArray.count>0) {
            NSString *statusStr=[NSString stringWithFormat:@"%@",[arrivalStatusArray objectAtIndex:indexPath.row] ];
           cell.statusLabel.text= [NSString stringWithFormat:@"【%@】",statusStr ];
           [Global resizeForLable:cell.statusLabel WithText:cell.statusLabel.text parentView:self.view];
           // [self resizeLabel:cell.statusLabel];
            if ([statusStr isEqualToString:@"未到货"]) {
                //NSLog(@"statusStr===%@",statusStr);
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                 cell.confirmArrivalBtn.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                [cell.confirmArrivalBtn setUserInteractionEnabled:YES];
                [cell.confirmArrivalBtn setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
            }

            if ([statusStr isEqualToString:@"部分到货"]) {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                 cell.confirmArrivalBtn.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                  [cell.confirmArrivalBtn setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                [cell.confirmArrivalBtn setUserInteractionEnabled:YES];
            }
            if ([statusStr isEqualToString:@"已到货"]) {
            [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                 cell.confirmArrivalBtn.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
              //  [cell.confirmArrivalBtn.];
                [cell.confirmArrivalBtn setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                 //[cell.confirmArrivalBtn setTintColor:];
                [cell.confirmArrivalBtn setUserInteractionEnabled:NO];
            }
        }
        
        
        if (arrivalPriceArray.count>0) {
            float AvgPrice=[[arrivalPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            //  NSString *marketStr=[NSString stringWithFormat:@"¥%0.02f",[[inquiryPriceArray objectAtIndex:indexPath.row] floatValue]];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
           // cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[arrivalPriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (arrivalDateArray.count>0) {
            cell.dateLabel.text=[arrivalDateArray objectAtIndex:indexPath.row];
        }
        if (arrivalGuideNameArray.count>0) {
            NSString *guideNameStr=[arrivalGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                cell.guideNameLabel.text=guideNameStr;
            }
            else
            {
                cell.guideNameLabel.text=@"未填写";
            }
            [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
           // [self resizeLabel:cell.guideNameLabel];
            CGRect frame=cell.dateTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
            cell.dateTagLabel.frame=frame;
            
            CGRect frame1=cell.dateLabel.frame;
            frame1.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame1;
            
            
        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (arrivalNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[arrivalNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (arrivalWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%@",[Global floatConvertPercentile:[[arrivalWeightArray objectAtIndex:indexPath.row] floatValue]]];
        }

        if (arrivalProductNameArray.count>0) {
            nameStr=[NSString stringWithFormat:@"%@",[arrivalProductNameArray objectAtIndex:indexPath.row]];
           // cell.productNameLabel.text=nameStr;//[shopCartMarketArray objectAtIndex:indexPath.row];
            if ([numberStr floatValue]>1) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }

           // [self resizeLabel:cell.productNameLabel];
            [Global resizeForLable:cell.productNameLabel WithText:cell.productNameLabel.text parentView:self.view];
            
            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+17;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;
            
        }
        
        
        if (indexPath.row == [arrivalNumArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //    NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
            
        }
        return cell;
    }
    else if (tableView==_detailTableView)
    {
        static NSString * const  ChangeTableViewCellIdentifier = @"ChangeTableViewCellIdentifier";
        ConfirmArrivalTableViewCell *cell=( ConfirmArrivalTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ChangeTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ConfirmArrivalTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (detailUrlArray.count>0) {
            if ([[detailUrlArray objectAtIndex:indexPath.row] length]>0) {
                [cell.productImageView setImageWithURL:[NSURL URLWithString:[detailUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.productImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (detailAttributesArray.count>0) {
            if ([detailAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[detailAttributesArray objectAtIndex:indexPath.row]];
                
            }
            // [self resizeLabel: cell.attributesLabel];
            [Global resizeForLable:cell.attributesLabel WithText:cell.attributesLabel.text parentView:self.view];
            
            CGRect frame= cell.weightTagLabel.frame;
            if ([[detailAttributesArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame1= cell.weightLabel.frame;
            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.weightLabel.frame=frame1;
            
        }

        if (detailWeightArray.count>0) {
            cell.weightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[detailWeightArray objectAtIndex:indexPath.row] floatValue]];
           // [self resizeLabel:cell.weightLabel];
            [Global resizeForLable:cell.weightLabel WithText:cell.weightLabel.text parentView:self.view];

            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.weightLabel.frame.origin.x+cell.weightLabel.frame.size.width+12;
            cell.priceLabel.frame=frame1;
        }
        if (detailLinePriceArray.count>0) {
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[detailLinePriceArray objectAtIndex:indexPath.row] floatValue]];
   
        }
        if (detailStoreAddressArray.count>0) {
            cell.storeAddressLabel.text=[detailStoreAddressArray objectAtIndex:indexPath.row];
            
        }
        if (detailProductNameArray.count>0) {
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[detailProductCodeArray objectAtIndex:indexPath.row],[detailProductNameArray objectAtIndex:indexPath.row]];//[detailProductNameArray objectAtIndex:indexPath.row];
        }
        if (detailStatusArray.count>0) {
            NSString *statusStr=[detailStatusArray objectAtIndex:indexPath.row];
            if ([statusStr isEqualToString:@"Y"]) {
                 cell.statusLabel.text=@"已到货";
                [cell.statusImageView setImage:[UIImage imageNamed:@"bukexuanze_.png"]];
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                [cell setUserInteractionEnabled:NO];
            }
            else {
                [cell.statusImageView setImage:[UIImage imageNamed:@"xuanze_hight1.png"]];
                cell.statusLabel.text=@"未到货";
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                [cell setUserInteractionEnabled:YES];
                NSString *lineIdStr=[detailLineIdArray objectAtIndex:indexPath.row];
                [selectLineID addObject:lineIdStr];
            }

           
        }
//        if (contacts.count>0) {
//            
//            NSMutableDictionary *dic = [contacts objectAtIndex:indexPath.row];
//            if ([[dic objectForKey:@"checked"] isEqualToString:@"NO"]) {
//                [dic setObject:@"NO" forKey:@"checked"];
//                
//                [cell setChecked:NO];
//                
//            }else {
//                [dic setObject:@"YES" forKey:@"checked"];
//                [cell setChecked:YES];
//            }
//        }


        cell.dotLineLabel.hidden=NO;
        if (indexPath.row==detailUrlArray.count-1) {
            cell.dotLineLabel.hidden=YES;
        }
        return cell;
        
    }
    
    else if (tableView==_resultGuideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if (tableView==_arrivalDetailTableView)
    {
        static NSString * const  ChangeTableViewCellIdentifier = @"ChangeTableViewCellIdentifier";
        UpCounterDetailTableViewCell *cell=( UpCounterDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ChangeTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"UpCounterDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (arrivalDetailUrlArray.count>0) {
            if ([[arrivalDetailUrlArray objectAtIndex:indexPath.row] length]>0) {
                
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[arrivalDetailUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (arrivalDetailWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[arrivalDetailWeightArray objectAtIndex:indexPath.row] floatValue]];
           // [self resizeLabel: cell.resultProductWeightLabel];
              [Global resizeForLable:cell.resultProductWeightLabel WithText:cell.resultProductWeightLabel.text parentView:self.view];
        }
        if (arrivalDetailAttributesArray.count>0) {
            if ([arrivalDetailAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[arrivalDetailAttributesArray objectAtIndex:indexPath.row]];
                
            }
           // [self resizeLabel: cell.attributesLabel];
             [Global resizeForLable:cell.attributesLabel WithText:cell.attributesLabel.text parentView:self.view];
            
            CGRect frame= cell.weightTagLabel.frame;
            if ([[arrivalDetailAttributesArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame1= cell.resultProductWeightLabel.frame;
            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.resultProductWeightLabel.frame=frame1;
            
        }

        
        if (arrivalDetailLinePriceArray.count>0) {
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%@",[arrivalDetailLinePriceArray objectAtIndex:indexPath.row]];
            CGRect frame=cell.resultProductPriceLabel.frame;
            frame.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+10;
            cell.resultProductPriceLabel.frame=frame;
        }
        if (arrivalReceiverArray.count>0) {
            cell.receiverLabel.text=[arrivalReceiverArray objectAtIndex:indexPath.row];
        }
        if (arrivalDetailProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[arrivalDetailProductCodeArray objectAtIndex:indexPath.row],[arrivalDetailProductNameArray objectAtIndex:indexPath.row]];
           // cell.receiverLabel.text=receiverGuideNameStr;
        }
        if (arrivalDetailStoreAddressArray.count>0) {
            cell.storeAddressLabel.text=[arrivalDetailStoreAddressArray objectAtIndex:indexPath.row];
        }
        cell.dotLineLabel.hidden=NO;
        if (indexPath.row==arrivalDetailUrlArray.count-1) {
            cell.dotLineLabel.hidden=YES;
        }
        return cell;
        
    }

    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_detailTableView) {
        [_searchTextField resignFirstResponder];
        [_resultTextView resignFirstResponder];

        ConfirmArrivalTableViewCell *cell = (ConfirmArrivalTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
            NSString *lineIdStr=[detailLineIdArray objectAtIndex:indexPath.row];
            if (![selectLineID containsObject:lineIdStr]) {
                [selectLineID addObject:lineIdStr];
                [cell.statusImageView setImage:[UIImage imageNamed:@"xuanze_hight1.png"]];
                //    [selectGuideValueArray addObject:cell.valueTextField.text];
                
            }
            
            
       // }
        else {
    
            if ([selectLineID containsObject:lineIdStr]) {
                [selectLineID removeObject:lineIdStr];
                [cell.statusImageView setImage:[UIImage imageNamed:@"xuanze_normal.png"]];
                // [selectGuideValueArray removeObject:cell.valueTextField.text];
                
            }
            
        }

    }
    else if(tableView==_arrivalDetailTableView)
    {
        
        _isLoad=@"Y";
        if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }
        commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
        commonProductDetailVC.delegate=self;
        commonProductDetailVC.codeStr=[arrivalDetailProductCodeArray objectAtIndex:indexPath.row];
        commonProductDetailVC.view.frame = CGRectMake(0,
                                                      0,
                                                      self.view.bounds.size.width,
                                                      self.view.bounds.size.height);
        
        [self addChildViewController:commonProductDetailVC];
        [self.view addSubview:commonProductDetailVC.view];

    }
    else if (tableView==_resultGuideListTableView) {
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        
        _resultGuideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_resultGuideListArrowImage setImage:closeImage];
            CGRect frame=_resultGuideListViewContainer.frame;
            
            frame.size.height=1;
            [_resultGuideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            isOpen=NO;
        }];
        _resultGuideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
       // [self resizeLabel1:_resultGuideNameLabel];
        CGRect frameK=_resultGuideNameLabel.frame;
        frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
        _resultGuideNameLabel.frame=frameK;
        
    }
    else if (tableView==_arrivalTableView)
    {
        [_searchTextField resignFirstResponder];
        [_resultTextView resignFirstResponder];

        [arrivalDetailUrlArray removeAllObjects];
        [arrivalDetailProductNameArray removeAllObjects];
         [arrivalDetailProductCodeArray removeAllObjects];
        [arrivalDetailLinePriceArray removeAllObjects];
        [arrivalReceiverArray removeAllObjects];
        [arrivalDetailStoreAddressArray removeAllObjects];
        [arrivalDetailAttributesArray removeAllObjects];
        [arrivalDetailWeightArray removeAllObjects];
        [self requestDetail:[arrivalNumArray objectAtIndex:indexPath.row]];
        [_detailScrollView setContentOffset:CGPointMake(0, 0)];
        [UIView animateWithDuration:0.5 animations:^{
            
            
            CGRect frame=_arrivalDetailViewContainer.frame;
            
            frame.origin.y=0;
            [_arrivalDetailViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            
        }];
        
    }

}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(ArrivalGoodShopCtarClick)]) {
        
        [self.delegate ArrivalGoodShopCtarClick];
    }
    
}

-(void)requestDetail:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"DocNum"];
        [HttpRequest requestData:@"StoreManager/DeliveryDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   //     NSLog(@"222=%@",severDataDict.dataDict);
                    receiverGuideNameStr=[severDataDict.dataDict objectForKey:@"GuideName"];
                    _detailResultLabel.text=[NSString stringWithFormat:@"(共%ld件,%0.02fg)",(long)[[severDataDict.dataDict objectForKey:@"Number"] integerValue],[[severDataDict.dataDict objectForKey:@"GramTotal"] floatValue]];
                    _detailNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                   // [self resizeLabel:_detailNumLabel];
                     [Global resizeForLable:_detailNumLabel WithText:_detailNumLabel.text parentView:self.view];
                    
                    CGRect frame5=_detailStatusLabel.frame;
                    frame5.origin.x=_detailNumLabel.frame.origin.x+_detailNumLabel.frame.size.width+2;
                    _detailStatusLabel.frame=frame5;
                    
                    NSString *statusStr=[severDataDict.dataDict objectForKey:@"DocStatus"];
                    _detailStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                    if ( [statusStr isEqualToString:@"未到货"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                    else if ([statusStr isEqualToString:@"部分到货"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                    
                    else if ([statusStr isEqualToString:@"已到货"]) {
                      [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                  //  [self resizeLabel:_detailStatusLabel];
                     [Global resizeForLable:_detailStatusLabel WithText:_detailStatusLabel.text parentView:self.view];
                 
                    if ([[severDataDict.dataDict objectForKey:@"GuideName"] length]>0) {
                          _detailManLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                    }
                    else
                    {
                         _detailManLabel.text=@"未填写";
                    }
                    [Global resizeForLable:_detailManLabel WithText:_detailManLabel.text parentView:self.view];
                  //  [self resizeLabel:_detailManLabel];
                    
//                    CGRect frame=_detailDateTagLabel.frame;
//                    frame.origin.x=_detailGuideNameLabel.frame.origin.x+_detailGuideNameLabel.frame.size.width+10;
//                    _detailDateTagLabel.frame=frame;
//                    
//                    CGRect frame0=_detailDateNameLabel.frame;
//                    frame0.origin.x=_detailDateTagLabel.frame.origin.x+_detailDateTagLabel.frame.size.width+2;
//                    _detailDateNameLabel.frame=frame0;
                    
                    
                    _detailRemarkView.text=[severDataDict.dataDict objectForKey:@"Remark"];
                   // [Global resizeTextView:_detailRemarkView contentStr:_detailRemarkView.text];
                    CGFloat height=  [Global heightForTextView:_detailRemarkView WithText:_detailRemarkView.text];
                    
                    CGRect frameA=_detailRemarkView.frame;
                    frameA.size.height=height;
                    _detailRemarkView.frame=frameA;
                    
                    CGRect frameD=_detailLastView.frame;
                    frameD.size.height=_detailRemarkView.frame.origin.y+_detailRemarkView.frame.size.height+10;
                    _detailLastView.frame=frameD;
                    
                    _detailDateNameLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    if ([[severDataDict.dataDict objectForKey:@"WhsFromName"] length]>0) {
                    _detailWhereLabel.text=[severDataDict.dataDict objectForKey:@"WhsFromName"];
                    }
                    else
                    {
                        _detailWhereLabel.text=@"未填写";
                    }
                   // [self resizeLabel:_detailWhereLabel];
                     [Global resizeForLable:_detailWhereLabel WithText:_detailWhereLabel.text parentView:self.view];
                    
                    CGRect frame4=_detailWhereTagLabel.frame;
                    frame4.origin.x=_detailManLabel.frame.origin.x+_detailManLabel.frame.size.width+10;
                    _detailWhereTagLabel.frame=frame4;
                    
                    CGRect frame6=_detailWhereLabel.frame;
                    frame6.origin.x=_detailWhereTagLabel.frame.origin.x+_detailWhereTagLabel.frame.size.width+3;
                    _detailWhereLabel.frame=frame6;
                    
                    
                    
                    NSMutableArray *returnDataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    float returnMonney=0;
                    for (int i=0; i<returnDataLineArray.count; i++) {
                        [arrivalDetailUrlArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [arrivalDetailProductNameArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemName"]];
                        [arrivalDetailProductCodeArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [arrivalDetailStoreAddressArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"WhsName"]];
                        NSString *lineTotalStr=[NSString stringWithFormat:@"%0.02f",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"LineTotal"] floatValue]];
                        [arrivalDetailLinePriceArray addObject:lineTotalStr];
                        [arrivalReceiverArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"GuideName"]];
                        returnMonney=returnMonney+[lineTotalStr floatValue];
                      //  NSString *weightStr=[NSString stringWithFormat:@"%d",[[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"] floatValue]];
                        [arrivalDetailWeightArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Gram"]];
                        
                        [arrivalDetailAttributesArray addObject:[[returnDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                    }
                    
                    [_arrivalDetailTableView reloadData];
                    
                    CGRect frame1=_arrivalDetailTableView.frame;
                    frame1.size.height=120*arrivalDetailUrlArray.count;
                    _arrivalDetailTableView.frame=frame1;
                    
                    CGRect frame2=_detailLastView.frame;
                    frame2.origin.y=_arrivalDetailTableView.frame.origin.y+_arrivalDetailTableView.frame.size.height+10;
                    _detailLastView.frame=frame2;
                    
                    
                    
                    [_detailScrollView setContentSize:CGSizeMake(0, _detailLastView.frame.origin.y+ _detailLastView.frame.size.height)];
                    [_detailScrollView setScrollEnabled:YES];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                         [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)confirmArrivalClick:(NSUInteger)tag
{
    guideCodeStr=[Global getGuideCodeStr];
    _resultGuideNameLabel.text=[Global getGuideNameStr];
   // NSLog(@"_resultGuideNameLabel.text===%@",_resultGuideNameLabel.text);
   // [self resizeLabel1:_resultGuideNameLabel];
    [Global resizeForLable:_resultGuideNameLabel WithText:_resultGuideNameLabel.text parentView:self.view];
    // [self resizeLabel1:_resultGuideNameLabel];
    CGRect frameK=_resultGuideNameLabel.frame;
    frameK.origin.x=_resultGuideListArrowImage.frame.origin.x-frameK.size.width-5;
    _resultGuideNameLabel.frame=frameK;

    [detailUrlArray removeAllObjects];
    [detailStoreAddressArray removeAllObjects];
    [detailLineIdArray removeAllObjects];
    
    [detailProductNameArray removeAllObjects];
    [detailProductCodeArray removeAllObjects];
    [detailLinePriceArray removeAllObjects];

    [detailWeightArray removeAllObjects];
    [detailAttributesArray removeAllObjects];
    [detailStatusArray removeAllObjects];
    [selectLineID removeAllObjects];
 
   // [contacts removeAllObjects];

    [self requestArrivalDetail:[arrivalNumArray objectAtIndex:tag] ];
    [UIView animateWithDuration:0.5 animations:^{
        
        
        CGRect frame=_confirmArrivalViewContainer.frame;
        
        frame.origin.y=0;
        [_confirmArrivalViewContainer setFrame:frame];
        
    } completion:^(BOOL finished){
        
    }];

}
-(IBAction)confirmArrivalBtnClick:(id)sender
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        //        NSLog(@"findSkuAllCountArray===%@",findSkuAllCountArray);
        for (int i=0; i<selectLineID.count; i++) {
            NSString *lineIdStr = [selectLineID objectAtIndex:i] ;
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:lineIdStr forKey:@"ItemCode"];
            
            [mDocumentLine addObject:dic];
        }
        
        
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
         [params setObject:_arrivalNumLabel.text forKey:@"DocNum"];
        [params setObject:_resultTextView.text forKey:@"Remark"];
        [params setObject:guideCodeStr forKey:@"GuideCode"];
        [params setObject:mDocumentLine forKey:@"DataLine"];
         NSLog(@"paramsSUBMIT1111====%@",params);
        [HttpRequest requestData:@"StoreManager/AddDelivery" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    [arrivalNumArray removeAllObjects];
                    [arrivalProductNameArray removeAllObjects];
                    [arrivalNumberArray removeAllObjects];
                    [arrivalWeightArray removeAllObjects];
                    [arrivalGuideNameArray removeAllObjects];
                    [arrivalDateArray removeAllObjects];
                    [arrivalStatusArray removeAllObjects];
                    [arrivalPriceArray removeAllObjects];
                    [selectLineID removeAllObjects];

                    _productPageIndex=0;
                    [self loadProductNextPage:_productPageIndex];
                    [UIView animateWithDuration:0.5 animations:^{
                        
                        [_rightScrollView setContentOffset:CGPointMake(0, 0)];
                        CGRect frame=_confirmArrivalViewContainer.frame;
                        
                        frame.origin.y=768;
                        [_confirmArrivalViewContainer setFrame:frame];
                        
                    } completion:^(BOOL finished){
                        
                    }];

                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                         [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)requestArrivalDetail:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"DocNum"];
        [HttpRequest requestData:@"StoreManager/DeliveryDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                      //  NSLog(@"222222=%@",severDataDict.dataDict);
                    _arrivalNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                   // [self resizeLabel:_arrivalNumLabel];
                    [Global resizeForLable:_arrivalNumLabel WithText:_arrivalNumLabel.text parentView:self.view];
                    CGRect frame=_arrivalStatusLabel.frame;
                    frame.origin.x=_arrivalNumLabel.frame.origin.x+_arrivalNumLabel.frame.size.width;
                    _arrivalStatusLabel.frame=frame;
                    
                    _detailTotalLabel.text=[NSString stringWithFormat:@"共%d件,%0.02fg",[[severDataDict.dataDict objectForKey:@"Number"] integerValue],[[severDataDict.dataDict objectForKey:@"GramTotal"] floatValue]];
                 //   NSLog(@"222=%@",_detailTotalLabel.text);
                    
                    NSString *statusStr=[severDataDict.dataDict objectForKey:@"DocStatus"];
                    _arrivalStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                     if ([statusStr isEqualToString:@"未到货"]) {
                          [_arrivalStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                     }
                    else if ( [statusStr isEqualToString:@"部分到货"])
                    {
                        [_arrivalStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                    }
                   else if ([statusStr isEqualToString:@"已到货"]) {
                        [_arrivalStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                   }
                   // [self resizeLabel:_arrivalStatusLabel];
                     [Global resizeForLable:_arrivalStatusLabel WithText:_arrivalStatusLabel.text parentView:self.view];
                    
                    CGRect frame3=_arrivalAddressTagLabel.frame;
                    frame3.origin.x=_arrivalStatusLabel.frame.origin.x+_arrivalStatusLabel.frame.size.width+10;
                    _arrivalAddressTagLabel.frame=frame3;
                    
                    CGRect frame4=_arrivalAddressLabel.frame;
                    frame4.origin.x=_arrivalAddressTagLabel.frame.origin.x+_arrivalAddressTagLabel.frame.size.width+3;
                    _arrivalAddressLabel.frame=frame4;
                    
                  //  _resultGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                   // [self resizeLabel1:_resultGuideNameLabel];
                    _resultTextView.text=[severDataDict.dataDict objectForKey:@"Remark"];
                  //  guideCodeStr=[severDataDict.dataDict objectForKey:@"GuideCode"];
                    if (_resultTextView.text.length>0) {
                        _resultTextViewImage.hidden=YES;
                        _resultTextViewLabel.hidden=YES;
                    }
                    else
                    {
                        _resultTextViewImage.hidden=NO;
                        _resultTextViewLabel.hidden=NO;
                    }
                    
                    _arrivalAddressLabel.text=[severDataDict.dataDict objectForKey:@"WhsFromName"];
                    NSMutableArray *arrivalArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                   
                    for (int i=0; i<arrivalArray.count; i++) {
                        [detailUrlArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        [detailLineIdArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"ItemCode"]];

                        [detailProductNameArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"ItemName"]];
                        [detailProductCodeArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                        [detailStoreAddressArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"WhsName"]];
                       // NSString *lineTotalStr=[NSString stringWithFormat:@"%0.02f",[[[arrivalArray objectAtIndex:i] objectForKey:@"LineTotal"] floatValue]];
                        [detailLinePriceArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"LineTotal"]];
                       
                    //    NSString *weightStr=[NSString stringWithFormat:@"%d",[[[arrivalArray objectAtIndex:i] objectForKey:@"Gram"] intValue]];
                        [detailWeightArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"Gram"]];
                        [detailAttributesArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"Attributes"]];
                        [detailStatusArray addObject:[[arrivalArray objectAtIndex:i] objectForKey:@"LineStatus"]];
                        
//                        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//                        [dic setValue:@"NO" forKey:@"checked"];
//                        [contacts addObject:dic];
                    }
                   // NSLog(@"detailLineIdArray====%@",detailLineIdArray);
                    [_detailTableView reloadData];
                    
                    CGRect frame1=_detailTableView.frame;
                    frame1.size.height=120*detailUrlArray.count;
                    _detailTableView.frame=frame1;
                    
                    CGRect frame2=_lastView.frame;
                    frame2.origin.y=_detailTableView.frame.origin.y+_detailTableView.frame.size.height+10;
                    _lastView.frame=frame2;
                    
                    if (_lastView.frame.origin.y+_lastView.frame.size.height>710) {
                        CGRect frame3=_lastView1.frame;
                        frame3.origin.y=_lastView.frame.origin.y+_lastView.frame.size.height+10;
                        _lastView1.frame=frame3;
                    }
                    else
                    {
                        CGRect frame3=_lastView1.frame;
                        frame3.origin.y=710;
                        _lastView1.frame=frame3;

                    }
                    
                    [_rightScrollView setContentSize:CGSizeMake(0, _lastView1.frame.origin.y+ _lastView1.frame.size.height)];
                    [_rightScrollView setScrollEnabled:YES];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                         [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
- (void)textViewDidChange:(UITextView *)textView
{
    if (textView==_resultTextView) {
        if (textView.text.length == 0) {
            _resultTextViewImage.hidden=NO;
            _resultTextViewLabel.hidden=NO;
        }
        else
        {
            _resultTextViewImage.hidden=YES;
            _resultTextViewLabel.hidden=YES;
            
        }
        
    }
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField==_searchTextField) {
        [arrivalNumArray removeAllObjects];
        [arrivalProductNameArray removeAllObjects];
        [arrivalWeightArray removeAllObjects];
        [arrivalNumberArray removeAllObjects];
        [arrivalGuideNameArray removeAllObjects];
        [arrivalDateArray removeAllObjects];
        [arrivalStatusArray removeAllObjects];
        [arrivalPriceArray removeAllObjects];

        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchTextField resignFirstResponder];
    }
    
    return YES;

}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if (textView==_resultTextView) {
        [UIView animateWithDuration:0.3 animations:^{
        CGRect viewFrame=_rightScrollView.frame;
        viewFrame.origin.y=-(_lastView.frame.origin.y+_lastView.frame.size.height-_rightScrollView.contentOffset.y+370-768);
        _rightScrollView.frame=viewFrame;
             } completion:^(BOOL finished){
                   }];
//        if (_lastView.frame.origin.y+_lastView.frame.size.height+352>768) {
//            
//            
//            [UIView animateWithDuration:0.3 animations:^{
//                CGRect viewFrame=_confirmArrivalViewContainer.frame;
//                viewFrame.origin.y=-(_lastView.frame.origin.y+_lastView.frame.size.height+354-768);
//                _confirmArrivalViewContainer.frame=viewFrame;
//            } completion:^(BOOL finished){
//                
//            }];
//        }
        
    }
    
    
    return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    [_rightScrollView setContentOffset:CGPointMake(0, 0)];
    if (textView==_resultTextView) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect viewFrame=_rightScrollView.frame;
            viewFrame.origin.y=0;
            _rightScrollView.frame=viewFrame;
        } completion:^(BOOL finished){
            
        }];
        
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
